package com.woniuxy.yygh.order.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.yygh.common.result.Result;
import com.woniuxy.yygh.common.utils.AuthContextHolder;
import com.woniuxy.yygh.enums.OrderStatusEnum;
import com.woniuxy.yygh.model.order.OrderInfo;
import com.woniuxy.yygh.order.service.OrderService;
import com.woniuxy.yygh.vo.order.OrderQueryVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO: 用户订单信息
 * <P> Date: 2022/3/6:10:00
 * <P> Description:
 */
@RestController
@RequestMapping("/api/order/orderInfo")
public class OrderApiController {

    @Autowired
    private OrderService orderService;

    /**
     * TODO: 根据排班id和就诊人id 生成挂号的订单
     **/
    @PostMapping("/auth/submitOrder/{scheduleId}/{patientId}")
    public Result saveOrder(@PathVariable String scheduleId,
                            @PathVariable Long patientId) {
        Long orderId = orderService.saveOrder(scheduleId, patientId);
        return Result.ok(orderId);
    }

    /**
     * TODO:根据订单id查询订单详情
     **/
    @GetMapping("/auth/getOrders/{orderId}")
    public Result getOrders(@PathVariable String orderId) {
        OrderInfo orderInfo = orderService.getOrder(orderId);
        return Result.ok(orderInfo);
    }

    /**
     * TODO:获取用户的所有列表 分页
     **/
    @ApiOperation(value = "获取分页列表")
    @GetMapping("/auth/getAllOrder/{page}/{limit}")
    public Result getAllOrder(
            @PathVariable Long page,
            @PathVariable Long limit,
            OrderQueryVo orderQueryVo,
            HttpServletRequest request) {
        //设置当前用户id
        orderQueryVo.setUserId(AuthContextHolder.getUserId(request));

        Page<OrderInfo> pageParam = new Page<>(page, limit);

        IPage<OrderInfo> pageModel = orderService.selectPage(pageParam, orderQueryVo);
        return Result.ok(pageModel);
    }

    /**
        * TODO:获取所有订单的状态
    **/
    @ApiOperation(value = "获取订单状态")
    @GetMapping("/auth/getStatusList")
    public Result getStatusList() {
        return Result.ok(OrderStatusEnum.getStatusList());
    }

    /**
        * TODO:根据订单取消预约
    **/
    @GetMapping("/auth/cancelOrder/{orderId}")
    public Result cancelOrder(@PathVariable String orderId){
       boolean isCancel =  orderService.cancelOrder(orderId);
        return Result.ok(isCancel);
    }
}
